package gameLogic;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

final class Encrypter {

	private static final byte[] computeHash(String text) {
		MessageDigest digestor = null;
		try {
			digestor = MessageDigest.getInstance("SHA-256");
		} catch (NoSuchAlgorithmException e) {
		}
		digestor.reset();
		digestor.update(text.getBytes());
		return digestor.digest();
	}

	private static final String byteArrayToHexString(byte[] bytes) {

		StringBuffer result = new StringBuffer(bytes.length * 2);

		for (int i = 0; i < bytes.length; i++) {

			int number = bytes[i] & 0xff;
			if (number < 16) {
				result.append('0');
			}
			result.append(Integer.toHexString(number));
		}
		return result.toString().toUpperCase();
	}

	public static final String encrypt(String password) {
		return byteArrayToHexString(computeHash(password));
	}

}
